/**
 * @file epd_class.h
 * @brief High-level EPD class-style API (C) encapsulating HAL, driver, and gfx.
 */
#ifndef EPD_CLASS_H
#define EPD_CLASS_H

#include <stdint.h>
#include <stdbool.h>
#include "hal/epd_hal.h"
#include "driver/epd_ssd167x.h"
#include "gfx/epd_gfx.h"

#ifdef __cplusplus
extern "C" {
#endif

/** Voltage modes supported by the abstraction. Actual hardware may restrict options. */
typedef enum {
    EPD_VOLT_3V3 = 0,
    EPD_VOLT_5V0 = 1
} epd_voltage_mode_t;

/** Runtime context "class" */
typedef struct {
    epd_hal_ctx_t hal;
    epd_ssd167x_t dev;
    uint8_t *front_bw;
    uint8_t *front_ry;
    uint8_t *back_bw;
    uint8_t *back_ry;
    uint32_t plane_size_bytes;
    epd_voltage_mode_t volt_mode;
} EPD_Class;

/** Create class instance and allocate double buffers */
EPD_Class *EPD_Create(uint16_t width, uint16_t height);

/** Destroy class instance and free buffers */
void EPD_Destroy(EPD_Class *epd);

/** Initialize hardware and underlying driver */
epd_err_t EPD_Init(EPD_Class *epd, const epd_spi_config_t *cfg);

/** Set refresh rate advisory (1..30Hz, step 0.1Hz) */
epd_err_t EPD_SetRefreshRate(EPD_Class *epd, double hz);

/** Set voltage mode (3.3V or 5V) – returns unsupported if hardware lacks 5V */
epd_err_t EPD_SetVoltageMode(EPD_Class *epd, epd_voltage_mode_t mode);

/** Draw tri-color vertical stripes to back buffers */
epd_err_t EPD_DrawVerticalStripes(EPD_Class *epd);

/** Commit back buffers to the panel and swap front/back */
epd_err_t EPD_Commit(EPD_Class *epd);

/** Enter sleep (deep) */
epd_err_t EPD_Sleep(EPD_Class *epd, bool deep);

/** Load RGB565 framebuffer */
epd_err_t EPD_LoadRGB565(EPD_Class *epd, const uint16_t *rgb565);

#ifdef __cplusplus
}
#endif

#endif /* EPD_CLASS_H */